package com.archway.appframe.web.interceptor;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class DefaultSecurityInterceptor implements HandlerInterceptor {
	
	private static Logger log = LoggerFactory.getLogger(DefaultSecurityInterceptor.class);
	private static Map<String,String> supportedMethod=new HashMap<String,String>();
	static{
		supportedMethod.put("GET", "GET");
		supportedMethod.put("POST", "POST");
		log.trace("限制支持的请求方式为GET/POST");
	}
	
	@Override
	public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
		log.trace("request ContentType :" + request.getContentType());
		log.trace("request CharacterEncoding :" + request.getCharacterEncoding());
		log.trace("request Method :" + request.getMethod());
		log.trace("request ContextPath :" + request.getContextPath());
		log.trace("request Protocol :" + request.getProtocol());
		log.trace("request LocalAddr,Name,Port :" + request.getLocalAddr()+","+request.getLocalName()+","+request.getLocalPort());
		log.info("request RequestURI :" + request.getRequestURI());
		log.info(request.getContentLength()+"");
		//URL长度限制长度
//		IE : 2803
//		Firefox:65536
//		Chrome:8182
//		Safari:80000
//		Opera:190000
//		boolean isPass=true;
//		if(!supportedMethod.containsKey(request.getMethod())){
//			isPass=false;
//		}
//		return isPass;
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request,HttpServletResponse response, Object handler,ModelAndView modelAndView) throws Exception {
		log.trace("response ContentType :" + response.getContentType());
		log.trace("response CharacterEncoding :" + response.getCharacterEncoding());
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)throws Exception {

	}

}
